clear all
set more off
set matsize 10000
tempfile ubigeo temp


local lista trust_police trust_army trust_church trust_newsp trust_rtv trust_parties trust_regi trust_jury trust_parliament trust_jne trust_onpe
local controls schooling male rural native married head 

use mergedp8090, clear

egen voted_bn = rowmax(voted_blank voted_null)
recode voted_bn voted_blank voted_null (. = 0) if voted == 0

** LABELS
label var todoA80 "Army - 80s"
label var todoT80 "Terrorist - 80s"
label var todoA90 "Army - 90s"
label var todoT90 "Terrorist - 90s"

******* Results
drop if vote_matter == .
local lista vote_matter voted voted_blank voted_null voted_bn partN dem_works dem_matters1 gov_demo1 gov_auto1

local r = 1
foreach var in `lista' {
	replace `var' = `var' * 100 if `r' != 6
	reghdfe `var' todoA80 todoA90 todoT80 todoT90 `controls', abs(ubigeo1993 ubigeonac1993 i.ubigeo1993#i.ubigeonac1993 i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
	est store reg`r'
	sum `var' if e(sample) == 1
	local y = r(mean)
	sum todoA80 if e(sample) == 1 & todoA80
	local sda80 = r(mean)
	sum todoA90 if e(sample) == 1 & todoA90
	local sda90 = r(mean)
	sum todoT80 if e(sample) == 1 & todoT80
	local sdt80 = r(mean)
	sum todoT90 if e(sample) == 1 & todoT90
	local sdt90 = r(mean)
	local na80`r' = (round((100*(_b[todoA80]) * `sda80') / `y', 0.01)) 
	local na90`r' = (round((100*(_b[todoA90]) * `sda90') / `y', 0.01)) 	
	local nt80`r' = (round((100*(_b[todoT80]) * `sdt80') / `y', 0.01)) 
	local nt90`r' = (round((100*(_b[todoT90]) * `sdt90') / `y', 0.01)) 	
	local ++r
}

noisily estout reg* ///
using Table_B6_0.tex, style(tex) c(b(fmt(2) star) se(par fmt(2))) ///
	label collabels(, none) eqlabels(none) mlabels(, none) varlabel(_cons " $ Control $ ") starlevel(* .1 ** .05 *** .01) ///
	keep(todoA80 todoA90 todoT80 todoT90) ///
	order(todoA80 todoA90 todoT80 todoT90) ///
	stats(r2 N N_clust, fmt(%9.2f %9.0g) labels(`"$ R ^{2}$"' "Observations" "Clusters")) replace 

texdoc init Table_B6.tex, replace
tex \begin{table}[h]
tex \caption{Impact of armed conflict on voting, participation and democratic beliefs: 80s and 90s}
tex \label{tab:Table_B6}
tex \begin{center}
tex \resizebox{16cm}{!}{
tex \begin{tabular}{lcccccccccc} \hline \hline
tex \\
tex & Voting & \multicolumn{4}{c}{Voted in last elections}& Participation & \multicolumn{2}{c}{Democracy} & \multicolumn{2}{c}{Type of preferred gov.} \\
tex & matters & Yes & ...blank & ...null & ...blank or & organisations & works & matters & Democracy & Autocracy \\
tex &&&&&Null&&&&& \\
tex &(1) &(2) &(3) &(4) &(5) &(6) &(7) &(8) &(9) &(10) \\
tex \hline
tex \input{Table_B6_0.tex}
tex &&&&&&&&& \\
tex \multicolumn{8}{l}{\textbf{Effect of 1 s.d. change in conflict measure as \% of mean of dependent variable:}} \\
tex Army - 80s & `na801' & `na802' & `na803' & `na804' & `na805' & `na806' & `na807' & `na808' & `na809' & `na8010' \\
tex Army - 90s & `na901' & `na902' & `na903' & `na904' & `na905' & `na906' & `na907' & `na908' & `na909' & `na9010' \\
tex Terrorist - 80s & `nt801' & `nt802' & `nt803' & `nt804' & `nt805' & `nt806' & `nt807' & `nt808' & `nt809' & `nt8010' \\
tex Terrorist - 90s & `nt901' & `nt902' & `nt903' & `nt904' & `nt905' & `nt906' & `nt907' & `nt908' & `nt909' & `nt9010' \\
tex &&&&&&&&& \\
tex \hline
tex \end{tabular}}
tex \end{center}
tex \end{table}	
